<?php
use_helper('I18N');
?>
<div class="breadcrumbs" id="breadcrumbs">
<script type="text/javascript">
    try {
        ace.settings.check('breadcrumbs', 'fixed')
    } catch(e) {
    }

    $(function() {
        $("#cbo_topupAmount").change(function(){
            /*var result = parseFloat($(this).val()) * <?php //echo $usdToMyr;?>;*/
            var result = parseFloat($(this).val());
            var epointBalance = $('#epointBalance').val();
            $("#convertedAmount").autoNumericSet(result);
            $("#epointBalanceDisplay").autoNumericSet(epointBalance - result);
        });

        $("#submitLink").click(function(event){
            event.preventDefault();
            var answer = confirm("<?php echo __('Are you sure you want to reload MT4 Funds?')?>")
            if (answer == true) {
                waiting();
                $("#withdrawForm").submit();
            }
        });
        $("#withdrawForm").validate({
            messages : {
                transactionPassword: {
                    remote: "Security Password is not valid."
                }
            },
            rules : {
                "transactionPassword" : {
                    required : true
                    , remote: "/member/verifyTransactionPassword"
                }
            },
            submitHandler: function(form) {
                if ($("#mt4UserName").val() == "") {
                    alert("MT4 status is pending.");
                    return false;
                }
                var epointBalance = $('#epointBalance').val();
                var mt4Amount = $('#cbo_topupAmount').val();

                if (parseFloat(mt4Amount) <= 0) {
                    alert("MT4 Amount cannot be zero");
                    return false;
                }
                
                if (parseFloat(mt4Amount) > parseFloat(epointBalance)) {
                    alert("In-sufficient MG");
                    return false;
                }
                waiting();

                form.submit();
            }
        });
        $("#cbo_topupAmount").trigger("change");
    });
</script>

<ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="/member/memberRegistration"><?php echo __('Registration') ?></a>
        </li>
        <li class="active"><?php echo __('Reload MT4 Fund') ?></li>
    </ul>
    <!-- .breadcrumb -->

    <div class="nav-search" id="nav-search">
        <form class="form-search">
            <span class="input-icon">
                <input type="text" placeholder="Search ..." class="nav-search-input"
                       id="nav-search-input" autocomplete="off"/>
                <i class="icon-search nav-search-icon"></i>
            </span>
        </form>
    </div>
    <!-- #nav-search -->
</div>
    
<div class="page-content">
<!-- /.page-header -->

<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->

<?php include_component('component', 'alert', array('param' => $sf_user->getAttribute(Globals::SESSION_DISTID, 0))) ?>

<div class="row">
<div class="space-6"></div>

<div class="col-xs-12">
    <form action="/member/reloadTopup" id="withdrawForm" name="withdrawForm" method="post" class="form-horizontal" role="form">
        <h3 class="header smaller lighter green"><?php echo __('Reload MT4 Fund') ?></h3>
        
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="mt4UserName"><?php echo __('MT4 ID'); ?></label>

            <div class="col-sm-9">
                <input name="mt4UserName" type="text" id="mt4UserName"  readonly="readonly" value="<?php //echo $distributorDB->getMt4UserName(); ?>" class="col-xs-10 col-sm-5" />
            </div>
        </div>

        <div class="space-4"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="epointBalanceDisplay"><?php echo __('Reload MT4 Fund'); ?></label>

            <div class="col-sm-9">
                <input name="epointBalance" id="epointBalance" type="hidden"
                               value="<?php echo $ledgerBalance; ?>"/>

                <select name="mt4Amount" id="cbo_topupAmount" tabindex="2">
                    <?php
                    for ($i = 0; $i <= 100000; $i = $i + 1000) {
                        echo "<option value='".$i."'>".number_format($i, 0)."</option>";
                    }
                    ?>
                </select>&nbsp;USD
                <!--&nbsp;USD-->
                &nbsp;<?php //echo $systemCurrency; ?>
            </div>
        </div>

        <div class="space-4"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="epointBalanceDisplay"><?php echo __('MP Balance'); ?></label>

            <div class="col-sm-9">
                <input name="epointBalanceDisplay" type="text" id="epointBalanceDisplay" readonly="readonly" 
                       placeholder="<?php echo __('MP Balance'); ?>" value="" class="col-xs-10 col-sm-5" />                
            </div>
        </div>

        <div class="space-4"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="transactionPassword"><?php echo __('Security Password'); ?></label>

            <div class="col-sm-9">
                <input name="transactionPassword" type="password" id="transactionPassword"
                       placeholder="<?php echo __('Security Password'); ?>" value="" class="col-xs-10 col-sm-5" />
            </div>
        </div>

        <div class="space-4"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right"></label>

            <div class="col-sm-9">
                <font color="#dc143c"><?php echo __('Note : MT4 Fund Reload will take 2 business days. ') ?></font>
            </div>
        </div>

        <div class="space-4"></div>

        <div class="clearfix form-actions">
            <div class="col-md-offset-3 col-md-9">
                <button class="btn btn-info" type="button" id="submitLink">
                    <i class="icon-ok bigger-110"></i>
                    <?php echo __('Submit') ?>
                </button>
            </div>
        </div>
    </form>
</div>

<div class="vspace-sm"></div>

<!-- /span -->
</div>
<!-- /row -->

<div class="hr hr32 hr-dotted"></div>

<!-- /row -->

<script type="text/javascript" language="javascript">
var datagrid = null;
$(function() {
    datagrid = $("#datagrid").r9jasonDataTable({
        // online1DataTable extra params
        "idTr" : true, // assign <tr id='xxx'> from 1st columns array(aoColumns);
        "extraParam" : function(aoData) { // pass extra params to server
        },
        "reassignEvent" : function() { // extra function for reassignEvent when JSON is back from server
            reassignDatagridEventAttr();
        },

        // datatables params
        "bLengthChange": true,
        "bFilter": false,
        "bProcessing": true,
        "bServerSide": true,
        "bAutoWidth": false,
        "sAjaxSource": "/finance/reloadMT4FundList",
        "sPaginationType": "full_numbers",
        "aaSorting": [
            [1,'desc']
        ],
        "aoColumns": [
            { "sName" : "dist_id", "bVisible" : false,  "bSortable": true},
            { "sName" : "created_on",  "bSortable": true},
            { "sName" : "mt4_user_name",  "bSortable": true},
            { "sName" : "amount",  "bSortable": true},
            { "sName" : "status_code",  "bSortable": true},
            { "sName" : "remarks",  "bSortable": true}
        ]
    });
}); // end function

function reassignDatagridEventAttr() {
}
</script>

<div class="row">
<div class="space-6"></div>

<div class="col-xs-12">
    <h3 class="header smaller lighter green"><?php echo __('Reload MT4 Fund Status') ?></h3>

    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover" id="datagrid" border="0" width="100%">
            <thead>
            <tr>
                <th></th>
                <th><?php echo __('Date') ?></th>
                <th><?php echo __('MT4 ID') ?></th>
                <th><?php echo __('Amount') ?></th>
                <th><?php echo __('Status') ?></th>
                <th><?php echo __('Remarks') ?></th>
            </tr>
            </thead>
        </table>
    </div>

    <div class="space-4"></div>
</div>

<div class="vspace-sm"></div>

<!-- /span -->
</div>

<!-- PAGE CONTENT ENDS -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</div><!-- /.page-content -->